import React, { Component } from 'react';
import {
  BrowserRouter as Router,
  Redirect,
  Switch,
  Route
} from 'react-router-dom';
import { connect } from 'react-redux';
import PrivateRoute from './PrivateRoute';
import App from '../App';
import { Login } from '../components'

class IndexRouter extends Component {
    render() {
        return (
            <Router>
                <div>
                  <Switch>
                    <Route path="/login" component={Login}/>
                    <Route exact path="/" render={() => (<Redirect to="/app/dashboard" />)} />
                    <PrivateRoute path="/app"
                    component={App}
                    authenticated={this.props.authenticated}/>
                  </Switch>
                </div>
            </Router>
        )
    }
}
function mapStateToProps(state) {
    return {authenticated: state.auth.authenticated};
}
export default connect(mapStateToProps)(IndexRouter);
